TEMPLATE = app
CONFIG  += console c++11
CONFIG  -= app_bundle
CONFIG  -= qt
QT      -= core
QT      -= gui

TARGET  = HelloDarknet

#DEFINES += GPU CUDNN CUDNN_HALF
#NVCC_DEFS += -DGPU -DCUDNN -DCUDNN_HALF

win32{
    DEFINES += _TIMESPEC_DEFINED _SCL_SECURE_NO_WARNINGS _CRT_SECURE_NO_WARNINGS _CRT_RAND_S WIN32 _CONSOLE _LIB
}

DESTDIR = $$PWD/Bin


INCLUDEPATH += \
    $$PWD/darknet/inc \
    $$PWD/darknet/src \
    $$PWD/darknet/common \
    $$PWD/darknet/low-src \
    $$PWD/darknet/high-src

HEADERS += \
    darknet/low-src/activations.h \
    darknet/low-src/avgpool_layer.h \
    darknet/low-src/blas.h \
    darknet/low-src/col2im.h \
    darknet/low-src/convolutional_layer.h \
    darknet/low-src/crop_layer.h \
    darknet/low-src/deconvolutional_layer.h \
    darknet/low-src/dropout_layer.h \
    darknet/low-src/im2col.h \
    darknet/low-src/maxpool_layer.h \
    darknet/common/data.h \
    darknet/common/list.h \
    darknet/common/parser.h \
    darknet/common/stb_image.h \
    darknet/common/stb_image_write.h \
    darknet/src/activation_layer.h \
    darknet/src/batchnorm_layer.h \
    darknet/src/box.h \
    darknet/src/classifier.h \
    darknet/src/connected_layer.h \
    darknet/src/cost_layer.h \
    darknet/src/crnn_layer.h \
    darknet/src/dark_cuda.h \
    darknet/src/demo.h \
    darknet/src/detection_layer.h \
    darknet/src/gemm.h \
    darknet/src/gru_layer.h \
    darknet/src/image.h \
    darknet/src/iseg_layer.h \
    darknet/src/l2norm_layer.h \
    darknet/src/layer.h \
    darknet/src/local_layer.h \
    darknet/src/logistic_layer.h \
    darknet/src/lstm_layer.h \
    darknet/src/matrix.h \
    darknet/src/network.h \
    darknet/src/normalization_layer.h \
    darknet/src/option_list.h \
    darknet/src/region_layer.h \
    darknet/src/reorg_layer.h \
    darknet/src/rnn_layer.h \
    darknet/src/route_layer.h \
    darknet/src/shortcut_layer.h \
    darknet/src/softmax_layer.h \
    darknet/src/tree.h \
    darknet/src/upsample_layer.h \
    darknet/src/utils.h \
    darknet/src/yolo_layer.h \
    stable.h

SOURCES += \
    darknet/high-src/art.c \
    darknet/high-src/attention.c \
    darknet/high-src/captcha.c \
    darknet/high-src/cifar.c \
    darknet/high-src/classifier.c \
    darknet/high-src/coco.c \
    darknet/high-src/detector.c \
    darknet/high-src/dice.c \
#    darknet/high-src/go.c \
    darknet/high-src/instance-segmenter.c \
    darknet/high-src/lsd.c \
    darknet/high-src/nightmare.c \
    darknet/high-src/regressor.c \
    darknet/high-src/rnn.c \
    darknet/high-src/rnn_vid.c \
    darknet/high-src/segmenter.c \
    darknet/high-src/super.c \
    darknet/high-src/swag.c \
    darknet/high-src/tag.c \
    darknet/high-src/voxel.c \
    darknet/high-src/writing.c \
    darknet/high-src/yolo.c \
    darknet/low-src/activations.c \
    darknet/low-src/avgpool_layer.c \
    darknet/low-src/blas.c \
    darknet/low-src/col2im.c \
    darknet/low-src/convolutional_layer.c \
    darknet/low-src/crop_layer.c \
    darknet/low-src/deconvolutional_layer.c \
    darknet/low-src/dropout_layer.c \
    darknet/low-src/im2col.c \
    darknet/low-src/maxpool_layer.c \
    darknet/common/data.c \
    darknet/common/list.c \
    darknet/common/parser.c \
    darknet/common/utils.c \
    darknet/src/activation_layer.c \
    darknet/src/batchnorm_layer.c \
    darknet/src/box.c \
    darknet/src/compare.c \
    darknet/src/connected_layer.c \
    darknet/src/cost_layer.c \
    darknet/src/crnn_layer.c \
    darknet/src/dark_cuda.c \
    darknet/src/demo.c \
    darknet/src/detection_layer.c \
    darknet/src/gemm.c \
    darknet/src/gru_layer.c \
    darknet/src/image.c \
    darknet/src/image_opencv.cpp \
    darknet/src/iseg_layer.c \
    darknet/src/l2norm_layer.c \
    darknet/src/layer.c \
    darknet/src/local_layer.c \
    darknet/src/logistic_layer.c \
    darknet/src/lstm_layer.c \
    darknet/src/matrix.c \
    darknet/src/network.c \
    darknet/src/normalization_layer.c \
    darknet/src/option_list.c \
    darknet/src/region_layer.c \
    darknet/src/reorg_layer.c \
    darknet/src/rnn_layer.c \
    darknet/src/route_layer.c \
    darknet/src/shortcut_layer.c \
    darknet/src/softmax_layer.c \
    darknet/src/tree.c \
    darknet/src/upsample_layer.c \
    darknet/src/yolo_layer.c \
    main.c

#CUDA_SOURCES += \
#    darknet/low-src/cuda/activation_kernels.cu \
#    darknet/low-src/cuda/avgpool_layer_kernels.cu \
#    darknet/low-src/cuda/blas_kernels.cu \
#    darknet/low-src/cuda/col2im_kernels.cu \
#    darknet/low-src/cuda/convolutional_kernels.cu \
#    darknet/low-src/cuda/crop_layer_kernels.cu \
#    darknet/low-src/cuda/deconvolutional_kernels.cu \
#    darknet/low-src/cuda/dropout_layer_kernels.cu \
#    darknet/low-src/cuda/im2col_kernels.cu \
#    darknet/low-src/cuda/maxpool_layer_kernels.cu


OBJECTS_DIR = ./tmp
CUDA_OBJECTS_DIR = OBJECTS_DIR/../cuda_tmp

## This makes the .cu files appear in your project


# CUDA settings <-- may change depending on your system
win32-msvc*{
    CUDA_SDK = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0"   # Path to cuda SDK install
    CUDA_DIR = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0"   # Path to cuda toolkit install
    CUDNN_DIR = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0"   # Path to cudnn install
}

unix{
    CUDA_SDK = "/usr/local/cuda-10.0"   # Path to cuda SDK install
    CUDA_DIR = "/usr/local/cuda-10.0"   # Path to cuda toolkit install
    CUDNN_DIR = "/usr/local/cuda"   # Path to cudnn install
}

win32{
# DO NOT EDIT BEYOND THIS UNLESS YOU KNOW WHAT YOU ARE DOING....
    SYSTEM_NAME = x64        # Depending on your system either 'Win32', 'x64', or 'Win64'
}

unix{
    SYSTEM_NAME = ubuntu        # Depending on your system either 'Win32', 'x64', or 'Win64'
}
SYSTEM_TYPE = 64            # '32' or '64', depending on your system
CUDA_ARCH = sm_75           # Type of CUDA architecture,
                            # for example 'compute_10', 'compute_11', 'sm_10'
NVCC_OPTIONS = --use_fast_math

win32{
    INCLUDEPATH += $$PWD/3rd/pthreads/include
    QMAKE_LIBDIR += $$PWD/3rd/pthreads/lib
    LIBS += -lpthreadVC2

    QMAKE_CFLAGS_DEBUG += -MD
    QMAKE_CXXFLAGS_DEBUG += -MD

#    LIBS += -lkernel32 -luser32 -lWS2_32 -lNetAPI32 \
#                 -lAdvAPI32 -lWSock32

    LIBS　+= -lWS2_32 -lWSock32 -llegacy_stdio_definitions # -lmsvcrtd
#    QMAKE_LFLAGS += "/nodefaultlib:msvcrt"

    INCLUDEPATH += $$PWD/darknet/patch

    HEADERS += darknet/patch/gettimeofday.h \
        darknet/patch/darkunistd.h \
        darknet/patch/getopt.h

    SOURCES += darknet/patch/gettimeofday.c \
        darknet/patch/getopt.c

}

unix{
    LIBS += -lpthread
}

# include paths
INCLUDEPATH += $$CUDA_DIR/include \
    $$CUDNN_DIR/include

# library directories
QMAKE_LIBDIR += $$CUDA_DIR/lib64/ \
    $$CUDNN_DIR/lib64/ \
    $$CUDA_DIR/lib/x64/ \
    $$CUDNN_DIR/lib/x64/

## Add the necessary libraries
CUDA_LIBS = -lcuda -lcudart -lcublas -lcurand -lcudnn

# The following makes sure all path names (which often include spaces)
# are put between quotation marks
CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"')
LIBS += $$CUDA_LIBS

# Configuration of the Cuda compiler
CONFIG(debug, debug|release) {
    # Debug mode
    cuda.input  = CUDA_SOURCES
    cuda.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
    cuda.commands = $$CUDA_DIR/bin/nvcc $$NVCC_DEFS D_DEBUG $$NVCC_OPTIONS \
                    $$CUDA_INC $$NVCC_LIBS --machine $$SYSTEM_TYPE \
                    -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
    cuda.dependency_type = TYPE_C
    QMAKE_EXTRA_COMPILERS += cuda
}
else {
    # Release mode
    cuda.input = CUDA_SOURCES
    cuda.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
    cuda.commands = $$CUDA_DIR/bin/nvcc $$NVCC_DEFS $$NVCC_OPTIONS \
                    $$CUDA_INC $$NVCC_LIBS --machine $$SYSTEM_TYPE \
                    -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
    cuda.dependency_type = TYPE_C
    QMAKE_EXTRA_COMPILERS += cuda
}

DISTFILES += \
    darknet/high-src/detector-scipy-opencv.py \
    darknet/high-src/detector.py

